import { id } from 'element-plus/lib/locale'
import { request } from './index.js'

// 获取所有借阅历史信息
export const getAllBorrows = () => {
  return request({
    url: '/borrows'
  })
}

// 根据图书编号获取借阅信息
export const getBorrowsByBookId = (bookid) => {
  return request({
    url: `/borrowbookid/${bookid}`
  })
}

// 根据读者 id 获取借阅信息
export const getBorrowsByReaderId = (readerid) => {
  return request({
    url: `/borrowreaderid/${readerid}`
  })
}

// 根据借阅 id 删除借阅记录
export const deleteBorrowById = (id) => {
  return request({
    url: `/borrowdel/${id}`,
    method: 'delete'
  })
}

// 清空借阅历史记录
export const clearBorrows = () => {
  return request({
    url: `/borrowclear`,
    method: 'delete'
  })
}

// 借书功能
export const borrowBook = (data) => {
  return request({
    url: "/addborrow",
    method: 'post',
    data
  })
}

// 获取读者借阅了多少本图书
export const getReaderBorrowCount = (data) => {
  return request({
    url: '/borrowcount',
    method: 'post',
    data
  })
}

// 获取读者已借阅当前图书数量
export const getReaderBorrowNowCount = (data) => {
  return request({
    url: '/getrbnc',
    method: 'post',
    data
  })
}

// 还书
export const backBooks = (data) => {
  return request({
    url: '/backbook',
    method: 'post',
    data
  })
}

// 根据图书 id，检查该图书是否存在未归还
export const checkBookBack = (id) => {
  return request({
    url: `/getboknobor/${id}`,
    method: 'get'
  })
}